<template>
  <a-card class="layout-card">
    <SearchGroup
      :label-option="Data.labelOption"
      @handleSearch="handleSearch"
      @handleReset="reset"
      :searchOption="filterOption"
    />

    <a-table
      class="tablstyle"
      rowKey="id"
      :scroll="{ x: 1450 }"
      bordered
      :loading="loading"
      :pagination="false"
      :dataSource="list"
      :columns="columns()"
    >
      <template #bodyCell="{ column, record, index, text }">
        <template v-if="column.dataIndex == 'index'">
          {{ (curPage - 1) * pageSize + (index + 1) }}
        </template>
        <template v-if="['smyc', 'sjsfyc', 'sfSm'].includes(column.dataIndex)">
          {{ text === false ? '否' : '是' }}
        </template>
        <template v-if="column.dataIndex == 'operation'">
          <a-button type="link" @click="handleView(record)"> 查看试卷 </a-button>
        </template>
      </template>
    </a-table>
    <a-pagination
      class="pagination"
      :show-total="total => `共 ${total} 条`"
      :show-size-changer="false"
      show-quick-jumper
      v-model:current="curPage"
      v-model:pageSize="pageSize"
      :total="total"
    />
  </a-card>
</template>

<script lang="ts" setup name="examinformation">
import { columns } from './data'
import { getKmSimpAlleList } from '/@/api/organization/subjectManage'
import { getPaperList } from '/@/api/organization/examinationPaper'
import { reactive, onMounted } from 'vue'
import { useList } from '/@/hooks/web/useList'
import { useRouter } from 'vue-router'
const router = useRouter()

const Data = reactive({
  labelOption: [
    {
      labelWidth: 50,
      key: 'kmdm',
      type: 'Select',
      name: '科目',
      selectOption: [],
      fieldNames: { label: 'kmmc', value: 'kmdm' },
    },
    { name: '考生准考证号', key: 'ksbh', inputWidth: 180, labelWidth: 100 },
    { name: '考生姓名', key: 'xm', inputWidth: 180, labelWidth: 80 },
    { name: '册号', key: 'ch', inputWidth: 180, labelWidth: 50 },
    { name: '册内序号', key: 'cnxh', inputWidth: 180, labelWidth: 80 },
    {
      name: '是否扫描',
      key: 'sfsm',
      labelWidth: 70,
      selectOption: [
        { label: '是', value: 1 },
        { label: '否', value: 0 },
      ],
      inputWidth: 180,
    },
    {
      name: '存在异常',
      key: 'existsYcFlag',
      labelWidth: 70,
      selectOption: [{ label: '是', value: true }],
      inputWidth: 180,
    },
    {
      name: '0分类型',
      key: 'scoreFlag',
      labelWidth: 80,
      selectOption: [
        { label: '科目0分', value: 'km0ScoreFlag' },
        { label: '主观题0分', value: 'zgt0ScoreFlag' },
        { label: '客观题0分', value: 'kgt0ScoreFlag' },
      ],
      inputWidth: 180,
    },
    {
      name: '考生试卷类型',
      key: 'kssjlx',
      labelWidth: 100,
      selectOption: [
        { label: '标准答题卡', value: 'STANDARD' },
        { label: '非标准答题卡', value: 'NOT_STANDARD' },
        { label: '混合答题卡', value: 'MIX' },
      ],
      inputWidth: 180,
    },
  ],
} as any)

function handleSearch() {
  filterOption.value.km0ScoreFlag = undefined
  filterOption.value.zgt0ScoreFlag = undefined
  filterOption.value.kgt0ScoreFlag = undefined
  if (filterOption.value.scoreFlag == 'km0ScoreFlag') {
    filterOption.value.km0ScoreFlag = true
  } else if (filterOption.value.scoreFlag == 'zgt0ScoreFlag') {
    filterOption.value.zgt0ScoreFlag = true
  } else if (filterOption.value.scoreFlag == 'kgt0ScoreFlag') {
    filterOption.value.kgt0ScoreFlag = true
  }
  loadData()
}

async function getKmpyJd() {
  const { code, data } = await getKmSimpAlleList({ pageSize: 0 })
  if (code == 200) {
    data.forEach(item => (item.kmmc = `${item.kmdm}(${item.kmmc})`))
    Data.labelOption[0].selectOption = data.sort((a, b) => a.kmdm - b.kmdm)
  }
}

const { reset, loadData, filterOption, curPage, total, pageSize, list, loading } =
  useList(getPaperList)

function handleView(record) {
  router.push({
    name: 'FractionDetaile',
    query: {
      kmdm: record.kmdm,
      kmpyzt: 'FORMAL',
      xsXm: record.xm,
      queryType: 'queryByZkzh',
      kdkskmId: record.id,
    },
  })
}

onMounted(() => {
  getKmpyJd()
})
</script>
<style lang="less" module>
.yc {
  :global {
    background-color: #fff;

    .ant-upload-list {
      display: none;
    }

    .ant-form {
      @apply px-6px;
    }
  }
}
</style>
